//
//  __url_shop.swift
//  smosky
//
//  Created by zhuxietong on 2018/8/17.
//  Copyright © 2018年 tianrun. All rights reserved.
//

import Foundation
import soapp

extension JoTask {
    @discardableResult
    public func _surl(_ url:_SURL) ->JoTask {
        self.url_value = url.url
        return self
    }
}




public enum _SURLVertion:String {
    case v1_0 = "1.0"//艾维1.0
    case v1_1 = "1.1"
    public static var current:_SURLVertion = .v1_0
}




public enum _SURL:String{
    
    //团购
    case 团购首页 = "/apiv1/groups/index"
    case 团购商品详情 = "/apiv1/groups/goods"
    case 团购提交确认 = "/apiv1/groups/confirm"
    case 团购提交 = "/apiv1/groups/submit"
    case 我的团列表 = "/apiv1/groups/getteamlist"
    case 组团详情 = "/apiv1/groups/teamdetail"
    case 组团详情2 = "/apiv2/groups.team/detail"
    case 团购订单详情 = "/apiv1/groups/orderdetail"
    
    case 正在拼团列表 = "/apiv1/groups/goodsteams"
    case 团购确认收货 = "/apiv1/groups/orderfinish"
    
    case 获取某个团购订单评价 = "/apiv1/groups/comment"
    case 评论团购商品订单 = "/apiv1/groups/commentsubmit"
    
    case 团购商品评论列表 = "/apiv1/groups/commentslist"
    
    //商城
    case 商品分类 = "/apiv1/goods/category"
    case 商品列表 = "/apiv1/goods/goodslist"
    case 商品详情 = "/apiv1/goods/goodsdetail"
    case 商品推荐 = "/apiv1/goods/recommendlist"
    case 商户信息 = """
    {"1.0":"/apiv1/store/merch","1.1":"/apiv1/merch/merch"}
    """
    
    case 天润易购首页 = "/apiv1/index/merch"
    case 商城首页 = "/apiv1/index/index"
    case 商城品牌列表 = "/apiv2/merch.mlist/get_list"

    
    //收藏
    case 我收藏的商品 = "/apiv1/goods/favoritelist"
    case 商品收藏toggle = "/apiv1/goods/favorite"
    case 门店收藏toggle = "/apiv1/store/favorite"
    
    case 商户收藏list = "/apiv1/merch/favoritelist"
    case 商户收藏toggle = "/apiv1/merch/collect"


    //商户
    case 商户申请 = "/apiv1/merch/register"
    
    
    //购物车
    case 加入购物车 = "/apiv1/cart/add"
    case 更改购物车数量 = "/apiv1/cart/update"
    case 更改购物车选择状态 = "/apiv1/cart/select"
    case 移出购物车 = "/apiv1/cart/remove"
    
    //收货地址
    case 收货地址列表 = "/apiv1/member/addresslist"
    case 收货地址添加_修改 = "/apiv1/member/addresspost"
    case 默认收货地址设置 = "/apiv1/member/addresssetdefault"
    case 收货地址删除 = "/apiv1/member/addressdel"
    case 我的购物车 = "/apiv1/cart/getlist"
    
    
    case 物流公司查询 = "/apiv1/Util/getExpressList"
    case 订单物流 = "/apiv1/Util/express"

    //商城订单
    case 确认购物信息 = "/apiv1/order/confirm"
    case 订单列表 = "/apiv1/order/orderlist"
    case 取消订单 = "/apiv1/order/cancel"
    case 订单详情 = "/apiv1/order/orderdetail"
    case 订单支付 = "/apiv1/order/pay"
    case 订单支付v2 = "/apiv2/order.pay/main"
    case 订单支付v2_1 = "/apiv2/util.pay/main"


    case 线下核销地址 = "/apiv1/order/stores"
    
    //售后
    case 退换货校验 = "/apiv1/refund/refundconfirm"
    case 提交售后申请 = "/apiv1/refund/refundsubmit"
    
    case 售后列表 = "/apiv1/refund/refundlist"
    case 售后详情 = "/apiv1/refund/refunddetail"
    case 售后协商历史 = "/apiv1/refund/consulthistorey"
    case 取消售后 = "/apiv1/refund/refundcancel"
    case 收到换货商品 = "/apiv1/refund/receive"
    case 确认退货发货 = "/apiv1/refund/express"
    
    
    case 订单价格计算 = "/apiv1/order/caculate"
    case 订单提交 = "/apiv1/order/create"
    case 删除订单 = "/apiv1/order/delete"
    case 确认收货 = "/apiv1/order/finish"
    
    case 获取某个订单评价 = "/apiv1/order/comment"
    case 评论商品订单 = "/apiv1/order/commentsubmit"
    
    case 评论列表 = "/apiv1/goods/commentslist"
    
    case uploadImage = "/apiv1/Util/upload_img"
    
    
    
    
    public static var host = ""
    
    public var url:String{
        get{
            if _SURL.host.len < 0
            {
                fatalError("请配置 __url.shop.swift 文件中商城的host")
            }
            
            var path = self.rawValue.escapeHeadTailSpace()
            if self.rawValue.hasPrefix("{")
            {
                if let url_map = rawValue.swift_dict?.mutable_dictionary
                {
                    let version = _SURLVertion.current.rawValue
                    if let p = url_map.object(forKey: version) as? String
                    {
                        if p.len < 1
                        {
                            fatalError("URL 配置错误;\(self)")
                        }
                        path = p
                    }
                    else{
                        fatalError("URL 配置错误;\(self)")
                    }
                    
                }
            }
            
//            if self.isAoaoTestHost{
//                return "http://aoao.doncheng.cn"  + "/apiv1/" + path
//            }
//            
            
            return _SURL.host + path
        }
    }
    
    var isAoaoTestHost:Bool{
        get{
            switch self {
            case .团购首页,.团购商品详情:
                return true
            default:
                return true
            }
        }
    }

}

